﻿@{
    ViewBag.Title = "角色用户";
    Layout =null;
}
<div class="modal-body">
    <form id="editform" method="POST" name="editform" class="form-horizontal">
        <div class="alert alert-warning  alert-dismissible">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
            选中复选框点击保存即可授予相应关联模块按钮。
        </div>
        <div class="row">
            <div class="col-md-12">
                <div class="box box-primary box-solid">
                    <div class="box-header with-border">
                        <h3 class="box-title">模块按钮列表</h3>
                        <div class="box-tools">
                            <div class="input-group" style="width: 250px;">
                                <input type="text" class="form-control input-sm" placeholder="请输入名称进行模糊查询...">
                                <div class="input-group-btn">
                                    <a class="btn btn-sm btn-default"><i class="fa fa-search"></i></a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="box-body no-padding">
                        <div class="mailbox-jqgrid">
                            <table id="chosenFunctionList"></table>
                            <div id="chosenFunctionPager"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="box-footer text-right">
            <!--以下两种方式提交验证,根据所需选择-->
            <button type="button" onclick="formSubmit()" class="btn btn-success" data-btn-type="save" title="确定"><span class="bootstrap-dialog-button-icon fa fa-check"></span>确定</button>
            <button type="button" class="btn btn-danger" data-btn-type="cancel" data-dismiss="modal"><span class="bootstrap-dialog-button-icon fa fa-times"></span>取消</button>
        </div>
    </form>
</div>
<style>
    .modal-body {
        padding: 3px;
    }
</style>
@Html.Hidden("Id")
<script>
    $(function () {
        initChosenFunctionsGird();
    });

    var $chosenFunctionsGrid;

    //表单提交
    function formSubmit() {
        //判断是否选中有数据
        var rowData = $chosenFunctionsGrid.jqGrid("getGridParam", "selarrrow");
        if (!rowData.length) {
            ArtDialogContent("请选择关联模块按钮");
            return;
        }
        var json = "";
        for (var i = 0; i < rowData.length; i++) {
            var functionId = $chosenFunctionsGrid.jqGrid('getCell', rowData[i], "FunctionId"); //name是colModel中的一属性
            json += "{\"MenuButtonId\":\"" + $("#Id").val() + "\",\"FunctionId\":\"" + functionId + "\"},";
        }
        json = json.substring(0, json.length - 1);
        json = "[" + json + "]";
        UtilAjaxPostWait("/System/MenuButton/SaveMenuButtonFunction",
        {
            menuButtonFunctions: json
        },
        success);
    }

    //提交成功
    function success(data) {
        if (DialogAjaxResult(data)) {
            getHaveFunctionGridData();
            //是否继续添加
        }
    }

    //初始化表格
    function initChosenFunctionsGird() {
        $chosenFunctionsGrid = $("#chosenFunctionList").jgridview(
        {
            shrinkToFit: true,
            multiselect: true,
            url: "/System/MenuButton/GetAllFunctions",
            colModel: [
                { name: "FunctionId", hidden: true },
                { label: "系统代码", name: "AppCode", width: 80, fixed: true },
                { label: "区域", name: "Area", width: 80, fixed: true },
                { label: "控制器", name: "Controller", width: 100, fixed: true },
                { label: "名称", name: "Action", width: 150, fixed: true },
                { label: "界面", name: "IsPage", width: 40, align: "center", fixed: true, formatter: "YesOrNo" },
                { label: "备注", name: "Description", width: 250, fixed: true }
            ],
            postData: {
                id: $("#Id").val()
            },
            pager: "chosenFunctionPager",
            height: "300",
            rowNum: 500,
            rowList: [500, 800, 1000]
        });
    }

    //获取表格数据
    function getChosenFunctionsGridData() {
        UtilAjaxPost("/System/MenuButton/GetAllFunctions", { id: $("#Id").val() }, function (data) {
            GridReloadLoadOnceData($chosenFunctionsGrid, data);
        });
    };
</script>